package com.hspedu.outputstream;

import org.junit.jupiter.api.Test;

import java.io.*;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/22
 * @time 20:02
 */
public class FileCopy {
    public static void main(String[] args) {

        byte[] buffer = new byte[512];

        int readLen = 0;

        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        //拷贝一份news4
        try {
            fileInputStream = new FileInputStream("D:\\BaiduNetdiskDownload\\韩顺平2021基础学Java\\temp\\news4.txt");
            fileOutputStream = new FileOutputStream("D:\\BaiduNetdiskDownload\\韩顺平2021基础学Java\\temp\\news5.txt");

            while ((readLen = fileInputStream.read(buffer)) != -1){
                fileOutputStream.write(buffer,0,readLen);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    @Test
    public void deleteFile(){
        File file = new File("D:\\BaiduNetdiskDownload\\韩顺平2021基础学Java\\temp\\news5.txt");
        if (file.exists()){
            file.delete();
            System.out.println("删除成功");
        }
    }
}
